#pragma once

#include <string>
#include <list>
#include <set>
#include <vector>

#include "util/fs.h"

#include "part.h"


namespace html::tmplt
{

class Builder
{
public:
    using Parts = std::list<Part>;
    using Iter = Parts::iterator;

    explicit Builder(const fs::path &path);

    void operator()(Parts &result, std::set<fs::path> &deps);

private:
    const std::string title() const {
        return title_;
    }

    Parts buildFileRecursive(const fs::path &path, std::vector<fs::path> &includeLevels);

    Iter handlePart(const fs::path &path, Parts &parts, Iter current, std::vector<fs::path> &includeLevels);

    Iter handleIncludeCmd(const fs::path &path, Parts &parts, Iter current, const std::string &rawIncludedPath, std::vector<fs::path> &includeLevels);

    static Parts cut(const fs::path &path);

private:
    const std::string title_;
    const fs::path path_;

    std::set<fs::path> deps_;
};

} // namespace html::tmplt
